
	/**taken from http://www.java2s.com/Code/Java/Language-Basics/AclasstorepresentComplexNumbers.htm
	 */
	public class Complex {
	  /** The real part */
	  private double r;
	  /** The imaginary part */
	  private double i;

	  /** Construct a Complex */
	  Complex(double rr, double ii) {
	    r = rr;
	    i = ii;
	  }

	  /** Display the current Complex as a String, for use in
	   * println() and elsewhere.
	   */
	  public String toString() {
				if(this.r==0 && this.i==0)
					return "0";
				if(this.r==0)
					return this.i+"i";
				if(this.i==0)
					return this.r+"";
				if(this.i<0)
					return this.r+""+this.i+"i";
				return this.r+"+"+this.i+"i";
			
	  }

	  /** Return just the Real part */
	  public double getReal() {
	    return r;
	  }
	  /** Return just the Real part */
	  public double getImaginary() {
	    return i;
	  }
	  /** Return the magnitude of a complex number */
	  public double magnitude() {
	    return Math.sqrt(r*r + i*i);
	  }
	  
	  public static double magnitude(Complex c)
	  {
		return Math.sqrt((c.getReal()*c.getReal())+(c.getImaginary()*c.getImaginary()));
	  }

	  /** Add another Complex to this one
	   */
	  public void add(Complex other) {
	    
		  Complex temp=new Complex(0,0);
		  temp=add(this,other);
		  this.i=temp.getImaginary();
		  this.r=temp.getReal();
	  }

	  /** Add two Complexes
	   */
	  public static Complex add(Complex c1, Complex c2) {
	    return new Complex(c1.r+c2.r, c1.i+c2.i);
	  }

	  /** Subtract another Complex from this one
	   */
	  public Complex subtract(Complex other) {
	    return subtract(this, other);
	  }
	  
	  public static Complex Chi(double r, double y,int n) {
		  double d=(2*Math.PI*r*y)/n;
			return new Complex(Math.cos(d), Math.sin(d));
		
	  }
		
	  
	  
	  
	  
	  
	  

	  /** Subtract two Complexes
	   */
	  public static Complex subtract(Complex c1, Complex c2) {
	    return new Complex(c1.r-c2.r, c1.i-c2.i);
	  }

	  /** Multiply this Complex times another one
	   */
	  public void multiply(Complex other) {
	    Complex temp=new Complex(0,0);
	     temp=multiply(this,other);
		  this.i=temp.getImaginary();
		  this.r=temp.getReal();
	  }

	  /** Multiply two Complexes
	   */
	  public static Complex multiply(Complex c1, Complex c2) {
	    return new Complex(c1.r*c2.r - c1.i*c2.i, c1.r*c2.i + c1.i*c2.r);
	  }

	  /** Divide c1 by c2.
	   * @author Gisbert Selke.
	   */
	  public static Complex divide(Complex c1, Complex c2) {
	    return new Complex(
	      (c1.r*c2.r+c1.i*c2.i)/(c2.r*c2.r+c2.i*c2.i),
	      (c1.i*c2.r-c1.r*c2.i)/(c2.r*c2.r+c2.i*c2.i));
	  }
	  
	  /* Compare this Complex number with another
	   */
	  public boolean equals(Object o) {
	    if (!(o instanceof Complex))
	      throw new IllegalArgumentException(
	          "Complex.equals argument must be a Complex");
	    Complex other = (Complex)o;
	    return r == other.r && i == other.i;
	  }
	  
	  /* Generate a hashCode; not sure how well distributed these are.
	   */
	  public int hashCode() {
	    return (int)( r) |  (int)i;
	  }

	}
